//
//  CustomMoneyNotEnogh.m
//  HuoBao
//
//  Created by sky on 15/12/1.
//  Copyright © 2015年 jinxin. All rights reserved.
//

#import "CustomMoneyNotEnogh.h"



@interface CustomMoneyNotEnogh ()


@property (nonatomic, strong) void(^CancelAction)();
@property (nonatomic, strong) UIView *dangban;
@property (nonatomic, strong) UIView *bgview;

@end



@implementation CustomMoneyNotEnogh

@synthesize ChangeCardAction;

- (instancetype)initWithBankImName:(NSString *)Imname BankName:(NSString *)bankname{
    self = [super init];
    self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    
    self.dangban = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    self.dangban.backgroundColor = [UIColor blackColor];
    self.dangban.alpha = 0.3;
    [self addSubview:self.dangban];
    
    
    self.bgview = [[UIView alloc]initWithFrame:CGRectMake(35, SCREEN_HEIGHT/2 - 336/4 - 50, SCREEN_WIDTH - 70, 404/2)];
    self.bgview.backgroundColor = [LCCommon getColor:@"3d3e41"];
    self.bgview.alpha = 0;
    self.bgview.layer.cornerRadius = 4;
    [self addSubview:self.bgview];
    
    UILabel *titile = [self LabelWithRect:CGRectMake(0, 56/2,self.bgview.width, 22) textColor:[LCCommon getColor:@"ffffff"] textstr:@"卡内余额不足!" textfont:22 textstyle:NSTextAlignmentCenter];
    [self.bgview addSubview:titile];
    
    
    CGSize strsize = [bankname sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13]}];
    
    UIImage *bankimage = [UIImage imageNamed:Imname];
    
    UIImageView *bankvi = [[UIImageView alloc]initWithFrame:CGRectMake(self.bgview.width/2 - (strsize.width + 13 + 5)/2, titile.origin.y + 22 + 7, 13, 13)];
    bankvi.image = bankimage;
    [self.bgview addSubview:bankvi];
    
    
    UILabel *banknm = [self LabelWithRect:CGRectMake(bankvi.origin.x + 13 + 5, bankvi.origin.y, strsize.width, 13) textColor:[LCCommon getColor:@"b1b1b1"] textstr:bankname textfont:13 textstyle:NSTextAlignmentLeft];
    [self.bgview addSubview:banknm];
    
    
    
    UILabel *back = [self LabelWithRect:CGRectMake(0,banknm.origin.y + 13 + 25, self.bgview.width , 13) textColor:[LCCommon getColor:@"b1b1b1"] textstr:@"您可以返回修改自己投资金额或者更换" textfont:13 textstyle:NSTextAlignmentCenter];
    [self.bgview addSubview:back];
    
    
    
    
    UILabel *new = [self LabelWithRect: CGRectMake(0, back.origin.y + 13 + 3, self.bgview.width, 13) textColor:[LCCommon getColor:@"b1b1b1"] textstr:@"新的银行卡来进行投资。" textfont:13 textstyle:NSTextAlignmentCenter];
    [self.bgview addSubview:new];

    
    
    UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0, self.bgview.height - 45.5, self.bgview.width, .5)];
    line.backgroundColor = [LCCommon getColor:@"696969"];
    [self.bgview addSubview:line];
    
    [self makeLinewithRect:CGRectMake(self.bgview.width/2, line.origin.y, .5, 45) Color:[LCCommon getColor:@"696969"] addview:self.bgview];
    
    
    
    UIButton *dell = [[UIButton alloc]initWithFrame:CGRectMake(0, self.bgview.height - 45, line.size.width/2, 45)];
    [dell setTitle:@"修改投资金额" forState:UIControlStateNormal];
    [dell setTitleColor:[LCCommon getColor:@"ffffff"] forState:UIControlStateNormal];
    dell.titleLabel.font = [UIFont systemFontOfSize:16];
    [dell addTarget:self action:@selector(cancelBtnTap) forControlEvents:UIControlEventTouchUpInside];
    dell.backgroundColor = [UIColor clearColor];
    [self.bgview addSubview:dell];
    
    
    UIButton *changebtn = [[UIButton alloc]initWithFrame:CGRectMake(line.size.width/2, self.bgview.height - 45, line.size.width/2, 45)];
    [changebtn setTitle:@"更换银行卡" forState:UIControlStateNormal];
    [changebtn setTitleColor:[LCCommon getColor:@"ffffff"] forState:UIControlStateNormal];
    changebtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [changebtn addTarget:self action:@selector(changeBtnTap) forControlEvents:UIControlEventTouchUpInside];
    changebtn.backgroundColor = [UIColor clearColor];
    [self.bgview addSubview:changebtn];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(cancelBtnTap)];
    [self.dangban addGestureRecognizer:tap];
    
    return self;
}


-(UILabel *)LabelWithRect:(CGRect)rect textColor:(UIColor *)color textstr:(NSString *)str textfont:(int)font textstyle:(NSTextAlignment)aligment{
    UILabel *label = [[UILabel alloc] initWithFrame:rect];
    label.textColor = color;
    label.text = str;
    label.font = [UIFont systemFontOfSize:font];
    label.textAlignment = aligment;
    label.numberOfLines = 0;
    return label;
}

-(void)makeLinewithRect:(CGRect)rect Color:(UIColor *)color addview:(UIView *)vi{
    UIView *line = [[UIView alloc]initWithFrame:rect];
    line.backgroundColor = color;
    [vi addSubview:line];
}


- (void)showInView
{
    
    [UIView animateWithDuration:0.25 animations:^{
        self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
        [[UIApplication sharedApplication].keyWindow addSubview:self];
        self.bgview.backgroundColor = [LCCommon getColor:@"3d3e41"];
        self.bgview.alpha = 1;
    }completion:^(BOOL finished) {
        
    }];
}


- (void)changeBtnTap
{
    if (self.ChangeCardAction)
    {
        self.ChangeCardAction();
    }
}


- (void)cancelBtnTap
{
    if (self.CancelAction)
    {
        self.CancelAction();
    }
    [self dismiss];
}

- (void)dismiss
{
    self.CancelAction = nil;
    self.ChangeCardAction = nil;
    [self removeFromSuperview];
}


@end
